<template>
  <div>
    <!-- 监管部门评价 -->
    <template>
      <div class="btn-line">
        <a-select
          @change="handleSearch"
          style="width:200px"
          placeholder="请选择"
          v-model="dictId"
          @select="handleAction"
        >
          <a-select-option v-for="item in dict" :key="item.key" :value="item.key">
            {{ item.name }}
          </a-select-option>
        </a-select>
      </div>
      <div class="mt20">
        <a-table
          class="risk-mini-size-table "
          :loading="pagination.loading"
          :columns="dictId==1?dataColumns:dataColumns2"
          :data-source="dictId==1?dataList:dataListAct"
          :pagination="pagination"
          bordered
          @change="pageChange"
          rowKey="id"
          :scroll="{ x: true }"
        >
          <template slot="textOver" slot-scope="text">
            <span class="text-over" :title="text">{{ text }}</span>
          </template>
          <template slot="serialNumber" slot-scope="text, record">
            <a type="link" @click="handleDetail(record)">{{ text }}</a>
          </template>
          <template slot="isFlag" slot-scope="text">
            <span :title="text">{{ text?'是':'否' }}</span>
          </template>
          <template slot="isFinish" slot-scope="text">
            <span :title="text">{{ text?'是':'否' }}</span>
          </template>
          <template slot="threeFirstTime" slot-scope="text , record">
            <span :title="text" v-if="record.threeFirstTime == true">是</span>
            <span :title="text" v-if="record.threeFirstTime == false">否</span>
          </template>
          <template slot="file" slot-scope="text, record" v-if="record">
            <!-- <p v-for="(item, index) of record" :key="index">
              <a icon="download" @click="handlePreview(record)">{{ item.filename }}</a>
            </p> -->
          </template>

          <template slot="needOpt" slot-scope="text, record">
            <a-switch checked-children="是" un-checked-children="否" v-model="record.needOpt"/>
          </template>
          <template slot="associated" slot-scope="text, record, index">
            <template v-if="record.needOpt">
              <span>{{text}}</span>
            </template>
          </template>
        </a-table>
      </div>
    </template>
    <ChooseModal ref="choosepro" @ok="choosePro"></ChooseModal>
  </div>
</template>

<script>
import { getRiskAction, postRiskAction } from '@/api/manage';
import LuckSheetPaste from '@/components/tools/LuckSheetPaste';
import * as api from '@/api/api';
import ChooseModal from "../../evaluation/assessPro/chooseModal";
import { CommonMixis } from '@/mixins/CommonMixis';
export default {
  name: 'DataColBy2',
  mixins: [CommonMixis],
  components: {
    ChooseModal
  },
  data() {
    return {
      dict: [
        { name: '风险点评价', key: 1 },
        { name: '控制活动评价', key: 2 },
      ],
      dictId: 1,
      pagination: {
        current: 1,
        pageSize: 10,
        pageSizeOptions: ['10', '30', '50'],
        showTotal: (total, range) => {
          return range[0] + '-' + range[1] + ' 共' + total + '条';
        },
        total: 0,
        loading: false,
      },
      dataColumns: [
        { title: '评价单号', dataIndex: 'serialNumber', align: 'center', width: 130 , scopedSlots:{customRender:'serialNumber'}},
        { title: '项目名称', dataIndex: 'projectName', align: 'center', width: 120 },
        { title: '评价人',width: 120,dataIndex: 'receiveUser',},
        { title: '评价时间',width: 100,dataIndex: 'threeFirstTime',align: 'center'},
        { title: '关联问题单号', width: 120, dataIndex: 'questionNo'},
        { title: '问题描述',width: 100,dataIndex: 'questionDesc',align: 'center', scopedSlots: { customRender: 'textOver' } },
        { title: '三年内是否首次发现问题',width: 100,dataIndex: 'threeFirstTime',align: 'center', scopedSlots: { customRender: 'threeFirstTime' }},
        { title: '问题分类',width: 100,dataIndex: 'questionClassName',align: 'center',},
        { title: '问题评级',width: 100,dataIndex: 'questionGradeName',align: 'center',},
        { title: '整改是否完成',width: 100,dataIndex: 'isFinish',align: 'center', scopedSlots: { customRender: 'isFinish' }},
      ],
      dataColumns2: [
        {
          title: '评价单号',
          dataIndex: 'serialNumber',
          align: 'center',
          width: 120 ,
          scopedSlots:{customRender:'serialNumber'}
        },
        {
          title: '项目名称',
          dataIndex: 'projectName',
          align: 'center',
          width: 120
        },
        {
          title: '评价人',
          width: 120,
          dataIndex: 'receiveUser',
        },
        {
          title: '评价时间',
          width: 100,
          dataIndex: 'finishTime',
          align: 'center'
        },
        {
          title: '控制活动编号',
          width: 100,
          align:'center' ,
          dataIndex: 'riskActivityNo',},
        {
          title: '控制活动',
          width: 120,
          align:'center' ,
          dataIndex: 'riskActivity'
        },
        {
          title: '业务流程细项是否与实际一致',
          width: 120,
          align:'center' ,
          dataIndex: 'fitActual' ,
          scopedSlots: { customRender: 'fitActual' }
        },
        {
          title: '控制活动执行程度',
          width: 110,
          dataIndex: 'executeDegree',
          scopedSlots: { customRender: 'executeDegree' }
        },
        {
          title: '控制活动相关附件',
          width: 120,
          dataIndex: 'attachName',
          align:'center' ,
          scopedSlots: { customRender: 'attachName' }
        },
        { title: '阶段实际执行的控制活动', width: 120, dataIndex: 'expectTime' },
        {
          title: '控制活动是否需优化',
          width: 80,
          align:'center' ,
          dataIndex: 'needOpt',
          scopedSlots: { customRender: 'needOpt' }
        },
        {
          title: '关联优化单号',
          width: 80,
          align:'center' ,
          dataIndex: 'optNo',
        },
      ],
      dataList: [],
      dataListAct:[] ,
      url: {
        activityList:'/incEvaluateActivity/getEvaluateActPage', //活动
        getList:'/incEvaluateRisk/getMatrixRiskList', //风险
      },
    };
  },
  mounted() {
    let riskId  = this.$route.query.id
    let companyCode = this.$route.query.companyCode;
    let manageCode = this.$route.query.manageCode;
    let businessModelId = this.$route.query.businessModelId;
    this.$set(this.pagination , 'riskId' , riskId)
    this.$set(this.pagination , 'companyCode' ,companyCode)
    this.$set(this.pagination , 'manageCode' ,manageCode)
    this.$set(this.pagination , 'businessModelId' ,businessModelId)
    this.getInitData();
  },
  methods: {
    handleSearch(){
      this.pagination.current = 1;
      this.getInitData();
    },
    /**
     * 查询列表
     */
    pageChange(page) {
      this.pagination.current = page.current;
      this.pagination.pageSize = page.pageSize;
      this.getInitData();
    },
    linitData(){
      this.pagination.loading = true;
      getRiskAction(this.url.activityList, {
        pageNo: this.pagination.current,
        pageSize: this.pagination.pageSize,
        keyword: this.pagination.keyword,
        type:5 ,
        companyCode: this.pagination.companyCode,
        businessModelId: this.pagination.businessModelId,
        manageCode: this.pagination.manageCode,
        status: this.pagination.status,
        dataType: this.pagination.dataType,
        isOvertime:this.pagination.isOvertime,
        deptId:this.pagination.deptId,
      }).then(res => {
        const result = res.data;
        if (res.code === 0) {
          this.dataListAct = result.records;
          this.pagination.total = result.total;
        } else {
          this.$message.error('查询列表失败');
        }
      });
      this.pagination.loading = false;
    },
    handleDetail(item){
      var routeUrl = this.$router.resolve({
        path: `/internal/eva/deteva/2/` + item.orderId ,
        query:{fromMartrix:true}
      });
      window.open(routeUrl.href, '_blank');
    },
    handleAction(value){
      if (value == 1){
        this.$set(this.pagination , 'current' , 1)
        this.getInitData()
      }
      if (value == 2){
        this.$set(this.pagination , 'current' , 1)
        this.initData();
      }
    },

    getInitData() {
      this.pagination.loading = true;
      getRiskAction(this.url.getList, {
        pageNo: this.pagination.current,
        pageSize: this.pagination.pageSize,
        keyword: this.pagination.keyword,
        companyCode: this.pagination.companyCode,
        businessModelId: this.pagination.businessModelId,
        manageCode: this.pagination.manageCode,
        riskId:this.pagination.riskId ,
        status: this.pagination.status,
        type:5 ,
        dataType: this.pagination.dataType,
        isOvertime:this.pagination.isOvertime,
        deptId:this.pagination.deptId,
      }).then(res => {
        const result = res.data;
        if (res.code === 0) {
          this.dataList = result.records;
          this.pagination.total = result.total;
        } else {
          this.$message.error('查询列表失败');
        }
      });
      this.pagination.loading = false;
    },
  }
};
</script>
<style lang="scss" scoped>
@import '../../main.scss';
.mt20{
  margin-top: 20px;
}
</style>
